import requests
import json
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator

plt.rcParams['font.sans-serif'] = ['KaiTi']
plt.rcParams['font.serif'] = ['KaiTi']

def get_data2():
    url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_other&callback=jQuery34109115895667113716_1582869774819&_=1582869774820'
    headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36'}
    res = requests.get(url, headers=headers).text
    a = res.split("jQuery34109115895667113716_1582869774819(")
    b=a[1]
    d=b[0:-1]
    c = json.loads(d)
    data2 = json.loads(c['data'])
    return data2

def get_data3():
    url = "https://api.inews.qq.com/newsqa/v1/automation/foreign/daily/list?country=%E6%84%8F%E5%A4%A7%E5%88%A9&"
    headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36'}
    res = requests.get(url, headers=headers).text
    data3 = json.loads(res)
    return data3

def get_data4():
    url = "https://api.inews.qq.com/newsqa/v1/automation/foreign/daily/list?country=%E5%BE%B7%E5%9B%BD&"
    headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36'}
    res = requests.get(url, headers=headers).text
    data4 = json.loads(res)
    return data4




def china_data():
    datas=get_data2()["chinaDayList"]
    x1 = []
    y1 = []
    y2 = []
    i = 0
    for data in datas:
        x1.append(i+1)
        y1.append(int(data["confirm"]))
        y2.append(int(data["dead"]))
        i+=1
    print(y1)
    print(y2)
    
    plt.figure(num = "疫情全国累计图")
    plt.xlabel("日期，2019.1.20至今")
    plt.ylabel("人数")
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,90000)
    plt.plot(x1,y1,label = "全国累计确诊",color = "red")
    plt.plot(x1,y2,label = "全国累计死亡",color = "black")
    plt.xticks([])
    plt.legend()
    plt.show()


def italy_data():
    datas = get_data3()["data"]
    x1 = []
    y1 = []
    y2 = []
    i = 0
    for data in datas:
        x1.append(i+1)
        y1.append(int(data["confirm"]))
        y2.append(int(data["dead"]))
        i+=1
    print(y1)
    print(y2)
    print(len(y1))
    plt.figure(num = "疫情意大利累计图")
    plt.xlabel("日期，2019.1.31至今")
    plt.ylabel("人数")
    y_major_locator=MultipleLocator(10000)
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.yaxis.set_major_locator(y_major_locator)
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,100000)
    plt.plot(x1,y1,label = "意大利累计确诊",color = "red")
    plt.plot(x1,y2,label = "意大利累计死亡",color = "black")
    plt.xticks([])
    plt.legend()
    plt.show()

def germany_data():
    datas = get_data4()["data"]
    x1 = []
    y1 = []
    y2 = []
    i = 0
    for data in datas:
        x1.append(i+1)
        y1.append(int(data["confirm"]))
        y2.append(int(data["dead"]))
        i+=1
    print(y1)
    print(y2)
    plt.figure(num = "疫情德国累计图")
    plt.xlabel("日期，2019.1.31至今")
    plt.ylabel("人数")
    y_major_locator=MultipleLocator(10000)
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.yaxis.set_major_locator(y_major_locator)
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,50000)
    plt.plot(x1,y1,label = "德国累计确诊",color = "red")
    plt.plot(x1,y2,label = "德国累计死亡",color = "black")
    plt.xticks([])
    plt.legend()
    plt.show()


def total_data():
    datas2 = get_data2()["chinaDayList"]
    datas3 = get_data3()["data"]
    datas4 = get_data4()["data"]
    x1 = []
    x2 = []
    y1 = []
    y2 = []
    y3 = []
    y4 = []
    y5 = []
    y6 = []
    i = 0
    for data in datas2:
       
        if i >=17:
            x1.append(i-16)
            y1.append(int(data["confirm"]))
            y2.append(int(data["dead"]))
        i+=1
    print(y1)
    i = 0
    for data in datas3:
        x2.append(i+1)
        y3.append(int(data["confirm"]))
        y4.append(int(data["dead"]))
        i+=1
    print(len(x2))
    i = 0
    for data in datas4:
        if i>=3:
            y5.append(int(data["confirm"]))
            y6.append(int(data["dead"]))
        
        i+=1

    plt.figure(num = "总图")
    plt.xlabel("日期，2019.1.31至今")
    plt.ylabel("人数")
    y_major_locator=MultipleLocator(10000)
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.yaxis.set_major_locator(y_major_locator)
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,100000)
    plt.plot(x1,y1,label = "中国累计确诊",color = "red")
    plt.plot(x1,y2,label = "中国累计死亡",color = "#e8b004")
    plt.plot(x2,y3,label = "意大利累计确诊",color = "green")
    plt.plot(x1,y4,label = "意大利累计死亡",color = "gray")
    plt.plot(x1,y5,label = "德国累计确诊",color = "blue")
    plt.plot(x1,y6,label = "德国累计死亡",color = "black")
    plt.xticks([])
    plt.legend()
    plt.show()
china_data()